class Solution {
public:
    int citys(vector<vector<int> >& city)
    {
        int m = city.size();
        int n = city[0].size();
        vector<bool> vis(m, false);
        int count = 0;
        for (int i = 0; i < m; i++)
        {
            if (!vis[i])
            {
                count++;
                function<void(int)> dfs = [&](int i)->void {
                    vis[i] = true;
                    for (int j = 0; j < n; j++)
                    {
                        if (city[i][j] == 1 && !vis[j])
                            dfs(j);
                    }
                    };
                dfs(i);
            }
        }
        return count;
    }
};